import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    isLogin: false,
    userInfo: {
      phone: '',
      token: ''
    },
  },
  mutations: {
    setuserInfo(state, data) {
      state.isLogin = true
      state.userInfo.phone = data.data.phone
      state.userInfo.token = data.token
      // window.localStorage.setItem('token', data.token)
      // console.log(state.userInfo.phone, state.userInfo.token, this);
    },
    logOut(state) {
      state.isLogin = false
      state.userInfo = {
        phone: '',
        token: ''
      }
    }
  },
  actions: {
    setuserInfo({ commit }, data) {
      return new Promise(() => {
        setTimeout(() => {
          commit('setuserInfo', data)
        }, 0);
      })
    },
    logOut({ commit }) {
      return new Promise(() => {
        setTimeout(() => {
          commit('logOut')
        })
      })
    }
  }, modules: {
  }
})
